#include "Train.h"

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int ret = 0, x;
        for (int i = 0; i < timeSeries.size(); i++) {
            if (i < timeSeries.size() - 1)x = timeSeries[i + 1] - timeSeries[i];
            else x = duration;
            if (x >= duration) ret += duration;
            else ret += x;
        }
        return ret;
    }
};